home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Pascal / Snippets / 3D-Maze 1.0 / 3D-Maze.p next >
Encoding:
Text File  |  1995-08-06  |  17.2 KB  |  681 lines  |  [TEXT/PJMM]

  1. {• 3-D-Maze.p}
  2.  
  3. {• Updated and simplified by Kenneth A. Long at itty bitty bytes™.}
  4. {Nicely simplified, too - easy to convert to Pascal! Which, of course, made it even simpler!}
  5.  
  6. program ThreeDMaze;
  7.  
  8. {$ifc UNDEFINED THINK_PASCAL}
  9.     uses
  10.         Types, QuickDraw, Events, Windows, Dialogs, Fonts, Traps,{}
  11.         Memory, SegLoad, Scrap, ToolUtils, OSUtils, Menus, Resources, Devices, DiskInit;
  12. {$elsec}
  13. {Some new routine names for Think Pascal}
  14.     procedure AppendResMenu (theMenu: MenuHandle; theType: ResType);
  15.     inline
  16.         $A94D;
  17.     procedure GetMenuItemText (theMenu: MenuHandle; item: INTEGER; var itemString: Str255);
  18.     inline
  19.         $A946;
  20. {$endc}
  21.  
  22.  
  23.     const
  24.         I_OK = 1;
  25.         I_x = 2;
  26.         I_x3 = 3;
  27.         I_x5 = 4;
  28.         I_Rectangle1 = 5;
  29.  
  30.     type
  31.         view = record
  32.                 rows: array[0..5, 0..4] of Boolean;
  33.             end;
  34.  
  35.     type
  36.         viewpoint = record
  37.                 x, y: Integer;
  38.                 facing: Byte;
  39.             end;
  40.     var
  41.         gridBytes: Integer;
  42.         mazeImageAdd: array[0..7] of Ptr;
  43.         mazeRect: Rect;
  44.         mazeImage: array[0..7] of BitMap;
  45.         yourView: viewpoint;
  46.         youSee: view;
  47.         viewRects: array[0..15] of Rect;
  48.  
  49.         gScreenBitsBounds: Rect;    {To avoid all $IFC's}
  50.  
  51. {Important change: "maze" and "rectValues" are now in resources.}
  52. {IMHO, the "rectValues" would be better off calculated, in order to make the program}
  53. {easier to modify, but having the maze in a resource makes lots of sense!}
  54.  
  55.     type
  56.         MazeArr = array[0..15, 0..15] of Boolean;
  57.         MazeArrPtr = ^MazeArr;
  58.         MazeArrHnd = ^MazeArrPtr;
  59.     var
  60.         maze: MazeArrHnd;
  61.  
  62.     type
  63.         RectArr = array[0..29] of Integer;
  64.         RectArrPtr = ^RectArr;
  65.         RectArrHnd = ^RectArrPtr;
  66.     var
  67.         rectValues: RectArrHnd;
  68.  
  69.         myWindow: WindowPtr;
  70.         tempRect, temp2Rect: Rect;
  71.         index: Integer;
  72.         CtrlHandle: ControlHandle;
  73.         sTemp: Str255;
  74.         MyErr: OSErr;
  75.  
  76.         AppleMenu: MenuHandle;
  77.  
  78.         ExitDialog: Boolean;
  79.         DoubleClick: char;
  80.         myPt: Point;
  81.  
  82.  
  83.     procedure D_About;
  84.     begin
  85.         if Alert(2, nil) = 1 then
  86.             ;
  87.     end; {D_About}
  88.  
  89.  
  90.     procedure DrawMaze;
  91.         var
  92.             i: Integer;
  93.     begin
  94.         CopyBits(mazeImage[0], mazeImage[6], mazeRect, mazeRect, srcCopy, nil);
  95.         for i := 0 to 4 do
  96.             if youSee.rows[i][0] then
  97.                 CopyBits(mazeImage[1], mazeImage[6], viewRects[i], viewRects[i], srcCopy, nil);
  98.         if (youSee.rows[0][1]) then
  99.             CopyBits(mazeImage[4], mazeImage[6], viewRects[0], viewRects[0], srcCopy, nil);
  100.         if (youSee.rows[4][1]) then
  101.             CopyBits(mazeImage[4], mazeImage[6], viewRects[4], viewRects[4], srcCopy, nil);
  102.         if (youSee.rows[1][1]) then
  103.             CopyBits(mazeImage[5], mazeImage[6], viewRects[12], viewRects[12], srcCopy, nil);
  104.         if (youSee.rows[3][1]) then
  105.             CopyBits(mazeImage[5], mazeImage[6], viewRects[13], viewRects[13], srcCopy, nil);
  106.         for i := 1 to 3 do
  107.             if (youSee.rows[i][1]) then
  108.                 CopyBits(mazeImage[2], mazeImage[6], viewRects[i + 4], viewRects[i + 4], srcCopy, nil);
  109.         if (youSee.rows[1][2]) then
  110.             begin
  111.                 CopyBits(mazeImage[3], mazeImage[6], viewRects[1 + 7], viewRects[1 + 7], srcCopy, nil);
  112.                 CopyBits(mazeImage[5], mazeImage[6], viewRects[11 + (1 - 1) div 2 * 3], viewRects[11 + (1 - 1) div 2 * 3], srcCopy, nil);
  113.             end;
  114.         if (youSee.rows[3][2]) then
  115.             begin
  116.                 CopyBits(mazeImage[3], mazeImage[6], viewRects[3 + 7], viewRects[3 + 7], srcCopy, nil);
  117.                 CopyBits(mazeImage[5], mazeImage[6], viewRects[11 + (3 - 1) div 2 * 3], viewRects[11 + (3 - 1) div 2 * 3], srcCopy, nil);
  118.             end;
  119.  
  120.         if (youSee.rows[2][2]) then
  121.             CopyBits(mazeImage[3], mazeImage[6], viewRects[9], viewRects[9], srcCopy, nil);
  122.         if (youSee.rows[1][3]) then
  123.             CopyBits(mazeImage[5], mazeImage[6], viewRects[8], viewRects[8], srcCopy, nil);
  124.         if (youSee.rows[3][3]) then
  125.             CopyBits(mazeImage[5], mazeImage[6], viewRects[10], viewRects[10], srcCopy, nil);
  126.         CopyBits(mazeImage[6], myWindow^.portBits, mazeRect, mazeRect, srcCopy, nil);
  127.     end; {DrawMaze}
  128.  
  129.  
  130. {• A 'for' loop that creates 14 rectangles at an index of viewRects.}
  131. {• This is like "SetRect, OffsetRect, SetRect, OffsetRect" etc x 14.}
  132. {• Why only 14?  Because of the two outer walls of the 16 x 16 maze.}
  133.  
  134. {• The coordinate values are indexed times two for left, then zero}
  135. {• for top, then index times two for the bottom, and 185 for right.}
  136.  
  137.     procedure DoRects;
  138.         var
  139.             i: Integer;
  140.     begin
  141.         for i := 0 to 14 do
  142.             begin
  143.                 SetRect(viewRects[i], rectValues^^[i * 2], 0, rectValues^^[i * 2 + 1], 185);
  144.             end;
  145.     end;
  146.  
  147.  
  148.     procedure InitMyMenus;
  149.         const
  150.             Menu_1 = 1001;
  151.             Menu_2 = 1002;
  152.             Menu_3 = 1003;
  153.         var
  154.             tempMenu: MenuHandle;
  155.     begin
  156.         ClearMenuBar;
  157.  
  158.     {• Apple menu.}
  159.         tempMenu := GetMenu(Menu_1);
  160.         InsertMenu(tempMenu, 0);
  161.         AppendResMenu(tempMenu, 'DRVR');
  162.         AppleMenu := tempMenu;
  163.  
  164.     {• This menu is File.}
  165.         tempMenu := GetMenu(Menu_2);
  166.         InsertMenu(tempMenu, 0);
  167.  
  168.     {• This menu is Commands.}
  169.         tempMenu := GetMenu(Menu_3);
  170.         InsertMenu(tempMenu, 0);
  171.  
  172.         DrawMenuBar;
  173.     end;
  174.  
  175.  
  176.     procedure SetView;
  177.         var
  178.             theRows: array[0..5, 0..4] of Byte;
  179.             mx, my, i, j: Integer;
  180.     begin
  181.         case (yourView.facing) of
  182.             0: 
  183.                 begin
  184.                     for j := 0 to 1 do
  185.                         for i := 0 to 4 do
  186.                             begin
  187.                                 mx := yourView.x - 2 + i;
  188.                                 my := yourView.y - 3 + j;
  189.  
  190.                                 if (mx < 0) or (mx > 15) or (my < 0) or (my > 15) then
  191.                                     youSee.rows[i][j] := false
  192.                                 else
  193.                                     youSee.rows[i][j] := maze^^[my][mx];
  194.                             end;
  195.                     for j := 2 to 3 do
  196.                         for i := 1 to 3 do
  197.                             begin
  198.                                 mx := yourView.x - 2 + i;
  199.                                 my := yourView.y - 3 + j;
  200.                                 if (mx < 0) or (mx > 15) or (my < 0) or (my > 15) then
  201.                                     youSee.rows[i][j] := false
  202.                                 else
  203.                                     youSee.rows[i][j] := maze^^[my][mx];
  204.                             end;
  205.                 end;
  206.             1: 
  207.                 for i := 3 downto 0 do
  208.                     begin
  209.                         mx := yourView.x + i;
  210.                         for j := 0 to 4 do
  211.                             begin
  212.                                 my := yourView.y - 2 + j;
  213.                                 if (mx < 0) or (mx > 15) or (my < 0) or (my > 15) then
  214.                                     youSee.rows[j][-i + 3] := false
  215.                                 else
  216.                                     youSee.rows[j][-i + 3] := maze^^[my][mx];
  217.                             end;
  218.                     end;
  219.             2: 
  220.                 for j := 0 to 3 do
  221.                     begin
  222.                         my := yourView.y + 3 - j;
  223.                         for i := 0 to 4 do
  224.                             begin
  225.                                 mx := yourView.x - 2 + i;
  226.                                 if (mx < 0) or (mx > 15) or (my < 0) or (my > 15) then
  227.                                     youSee.rows[4 - i][j] := false
  228.                                 else
  229.                                     youSee.rows[4 - i][j] := maze^^[my][mx];
  230.                             end;
  231.                     end;
  232.             3: 
  233.                 for i := 0 to 3 do
  234.                     begin
  235.                         mx := yourView.x - 3 + i;
  236.                         for j := 0 to 4 do
  237.                             begin
  238.                                 my := yourView.y - 2 + j;
  239.                                 if (mx < 0) or (mx > 15) or (my < 0) or (my > 15) then
  240.                                     youSee.rows[4 - j][i] := false
  241.                                 else
  242.                                     youSee.rows[4 - j][i] := maze^^[my][mx];
  243.                             end;
  244.                     end;
  245.         end;
  246.     end; {SetView}
  247.  
  248.  
  249.     procedure MoveForward;
  250.     begin
  251.         case yourView.facing of
  252.             0: 
  253.                 if (not maze^^[yourView.y - 1][yourView.x]) then
  254.                     yourView.y := yourView.y - 1;
  255.             1: 
  256.                 if (not maze^^[yourView.y][yourView.x + 1]) then
  257.                     yourView.x := yourView.x + 1;
  258.             2: 
  259.                 if (not maze^^[yourView.y + 1][yourView.x]) then
  260.                     yourView.y := yourView.y + 1;
  261.             3: 
  262.                 if (not maze^^[yourView.y][yourView.x - 1]) then
  263.                     yourView.x := yourView.x - 1;
  264.         end; {case}
  265.         SetView;
  266.         DrawMaze;
  267.     end; {MoveForward}
  268.  
  269.     procedure TurnLeft;
  270.     begin
  271.         yourView.facing := BAnd(yourView.facing - 1, 3);
  272.  
  273.         SetView;
  274.         DrawMaze;
  275.     end;
  276.  
  277.     procedure TurnRight;
  278.     begin
  279.         yourView.facing := BAnd(yourView.facing + 1, 3);
  280.  
  281.         SetView;
  282.         DrawMaze;
  283.     end;
  284.  
  285.     procedure TurnAround;
  286.     begin
  287.         yourView.facing := BAnd(yourView.facing + 2, 3);
  288.  
  289.         SetView;
  290.         DrawMaze;
  291.     end;
  292.  
  293.  
  294.     procedure InitMaze;
  295.         var
  296.             i: Integer;
  297.             thePic: PicHandle;
  298.     begin
  299.         gridBytes := 28;        {• One byte per rectangle.}
  300.  
  301.         DoRects;
  302.  
  303.         SetRect(mazeRect, 0, 0, 216, 185);
  304.  
  305.         thePic := GetPicture(134);
  306.         DrawPicture(thePic, mazeRect);
  307.  
  308.         repeat        {• Do nothing until a mouseDown.}
  309.         until Button;
  310.  
  311.     {• Then run this loop.  It gets all six pictures, makes a new}
  312.     {• bitmap for each one, erases the mazeRect, draws and erases}
  313.     {• each one until the sixth one is drawn, then exits the loop.}
  314.         for i := 0 to 6 do
  315.             begin
  316.                 if i <> 6 then        {• If there are less than 6, get them.}
  317.                     thePic := GetPicture(128 + i);
  318.  
  319.         {• Make a new pointer to each one.}
  320.                 mazeImageAdd[i] := NewPtr(LongInt(28 * 185));
  321.  
  322.         {• If "no dice" crap out.}
  323.                 if mazeImageAdd[i] = nil then
  324.                     ExitToShell;
  325.  
  326.         {• Say what the b.a. and r.b. are for each.}
  327.                 mazeImage[i].baseAddr := QDPtr(mazeImageAdd[i]);
  328.                 mazeImage[i].rowBytes := gridBytes;    {• Originally 28.}
  329.  
  330.         {• Set a rect. for each bit immage, the same sizes.}
  331.                 SetRect(mazeImage[i].bounds, 0, 0, 224, 185);
  332.  
  333.         {• Erase the mazeRect and draw the picture if it's not the}
  334.         {• sixth one.}
  335.                 if (i <> 6) then
  336.                     begin
  337.                         EraseRect(mazeRect);
  338.                         DrawPicture(thePic, mazeRect);
  339. {$ifc UNDEFINED THINK_PASCAL}
  340.                         CopyBits(qd.thePort^.portBits, mazeImage[i], mazeRect, mazeRect, srcCopy, nil);
  341. {$elsec}
  342.                         CopyBits(thePort^.portBits, mazeImage[i], mazeRect, mazeRect, srcCopy, nil);
  343. {$endc}
  344.                     end;
  345.             end;
  346.     {• Your starting view is x-one, y-fourteen, facing in the zero}
  347.     {• direction (zero is one out of four clockwise, or toward top).}
  348.     {• So, on the 'maze' table, above, you are at the lower-right}
  349.     {• facing up.}
  350.         yourView.x := 1;
  351.         yourView.y := 14;
  352.         yourView.facing := 0;
  353.  
  354.     {• Now you just set whatever view you're facing, }
  355.     {• according to key hit values and a read by a switch!}
  356.         SetView;
  357.     end; {InitMaze}
  358.  
  359.     procedure HandleMenu (var doneFlag: Boolean; theMenu: Integer; theItem: Integer; var theInput: TEHandle);
  360.         const
  361.     {• List in the menu bar.}
  362.             List_Apple = 1001;
  363.             Item_About_Mazes = 1;
  364.     {• List in the menu bar.}
  365.             List_File = 1002;
  366.             Item_Quit = 1;
  367.     {• List in the menu bar.}
  368.             List_Commands = 1003;
  369.             Item_Forward = 1;
  370.             Item_Turn_Left = 2;
  371.             Item_Turn_Right = 3;
  372.             Item_Turn_Around = 4;
  373.         var
  374.             SavePort: GrafPtr;
  375.             DAName: Str255;
  376.             DNA: Integer;
  377.             BoolHolder: Boolean;
  378.     begin
  379.         case theMenu of
  380.             List_Apple: 
  381.                 case theItem of
  382.                     Item_About_Mazes: 
  383.                         D_About;
  384.                     otherwise
  385.                         begin
  386.                             GetPort(SavePort);
  387.                             GetMenuItemText(AppleMenu, theItem, DAName);
  388.                             DNA := OpenDeskAcc(DAName);
  389.                             SetPort(SavePort);
  390.                         end; {otherwise}
  391.                 end; {case theItem}
  392.  
  393.             List_File: 
  394.                 case theItem of
  395.                     Item_Quit: 
  396.                         doneFlag := TRUE;
  397.                 end;
  398.             List_Commands: 
  399.                 begin
  400.                     BoolHolder := SystemEdit(theItem - 1);
  401.                     if (BoolHolder = FALSE) then
  402.                         begin
  403.                             case (theItem) of
  404.                                 Item_Forward: 
  405.                                     MoveForward;
  406.                                 Item_Turn_Left: 
  407.                                     TurnLeft;
  408.                                 Item_Turn_Right: 
  409.                                     TurnRight;
  410.                                 Item_Turn_Around: 
  411.                                     TurnAround;
  412.                             end; {case theItem}
  413.                         end;
  414.                 end; {List_Commands}
  415.         end; {case theMenu}
  416.         HiliteMenu(0);
  417.     end; {HandleMenu}
  418.  
  419.  
  420. {• Initialize us so all our routines can be activated.}
  421.     procedure Init_P_D_Maze;
  422.     begin
  423.         myWindow := nil;
  424.         rectValues := RectArrHnd(GetResource('RctV', 128));
  425.         maze := MazeArrHnd(GetResource('Maze', 128));
  426.     end;
  427.  
  428. {• Close our window.}
  429.     procedure Close_P_D_Maze (whichWindow: WindowPtr; var theInput: TEHandle);
  430.     begin
  431.         if ((myWindow <> nil) and ((myWindow = whichWindow) or (whichWindow = WindowPtr(-1)))) then
  432.             begin
  433.                 DisposeWindow(myWindow);
  434.                 myWindow := nil;
  435.             end;
  436.     end;
  437.  
  438. {• Update our window, someone uncovered a part of us.}
  439.     procedure UpDate_P_D_Maze (whichWindow: WindowPtr);
  440.         var
  441.             SavePort: WindowPtr;
  442.     begin
  443.         if ((myWindow <> nil) and (myWindow = whichWindow)) then
  444.             begin
  445.                 GetPort(SavePort);
  446.                 SetPort(myWindow);
  447.                 DrawControls(myWindow);
  448.                 DrawMaze;
  449.                 SetPort(SavePort);
  450.             end;
  451.     end;
  452.  
  453. {• Open our window and draw everything.}
  454.     procedure Open_P_D_Maze (var theInput: TEHandle);
  455.         var
  456.             index: Integer;
  457.             dataBounds: Rect;
  458.             cSize: Point;
  459.     begin
  460.         if (myWindow = nil) then
  461.             begin
  462.                 myWindow := GetNewWindow(1, nil, WindowPtr(-1));
  463.                 SetPort(myWindow);
  464.  
  465.                 ShowWindow(myWindow);
  466.                 SelectWindow(myWindow);
  467.                 InitMaze;
  468.                 DrawMaze;
  469.             end
  470.         else
  471.             SelectWindow(myWindow);
  472.         DrawMaze;
  473.     end;
  474.  
  475. {• Handle action to our window, like controls.}
  476.     procedure Do_P_D_Maze (var myEvent: EventRecord; var theInput: TEHandle);
  477.         var
  478.             RefCon: Integer;
  479.             code: Integer;
  480.             theValue: Integer;
  481.             whichWindow: WindowPtr;
  482.             myPt: Point;
  483.             theControl: ControlHandle;
  484.  
  485.     begin    {• Start of Window handler.}
  486.         if myWindow <> nil then
  487.             begin
  488.                 code := FindWindow(myEvent.where, whichWindow);
  489.                 if ((myEvent.what = mouseDown) and (myWindow = whichWindow)) then
  490.                     begin
  491.                         myPt := myEvent.where;
  492.                         GlobalToLocal(myPt);
  493.                     end;
  494.                 if ((myWindow = whichWindow) and (code = inContent)) then
  495.                     begin
  496.                         code := FindControl(myPt, whichWindow, theControl);
  497.                         if (code <> 0) then
  498.                             code := TrackControl(theControl, myPt, nil);
  499.                     end;
  500.             end;
  501.     end; {Do_P_D_Maze}
  502.  
  503.     var
  504.         doneFlag: Boolean;
  505.         Is_A_Dialog: char;
  506.         stillInGoAway: Boolean;
  507.         ch: char;
  508.         code: Integer;
  509.         theMenu, theItem: Integer;
  510.         chCode: Integer;
  511.         mResult: LongInt;
  512.         whichWindow: WindowPtr;
  513.         myEvent: EventRecord;
  514.         theInput: TEHandle;
  515.         OldRect: Rect;
  516.         SavePort: GrafPtr;
  517.  
  518. begin {Main program}
  519. {$IFC UNDEFINED THINK_PASCAL}
  520.     InitGraf(@qd.thePort);
  521.     InitFonts;
  522.     FlushEvents(everyEvent, 0);
  523.     InitWindows;
  524.     InitMenus;
  525.     TEInit;
  526.     InitDialogs(nil);
  527.     InitCursor;
  528. {$ENDC}
  529.  
  530. {$ifc UNDEFINED THINK_PASCAL}
  531.     gScreenBitsBounds := qd.screenBits.bounds;
  532. {$elsec}
  533.     gScreenBitsBounds := screenBits.bounds;
  534. {$endc}
  535.  
  536.     doneFlag := FALSE;
  537.  
  538.     InitMyMenus;
  539.     theInput := nil;
  540.     Init_P_D_Maze;
  541.     Open_P_D_Maze(theInput);
  542.  
  543.     repeat
  544.         if (theInput <> nil) then
  545.             TEIdle(theInput);
  546.  
  547.         SystemTask;
  548.         if (GetNextEvent(everyEvent, myEvent)) then
  549.             begin
  550.                 code := FindWindow(myEvent.where, whichWindow);
  551.                 case myEvent.what of
  552.                     mouseDown: 
  553.                         if (code = inMenuBar) then
  554.                             begin
  555.                                 mResult := MenuSelect(myEvent.where);
  556.                                 theMenu := HiWord(mResult);
  557.                                 theItem := LoWord(mResult);
  558.                                 HandleMenu(doneFlag, theMenu, theItem, theInput);
  559.                             end
  560.                         else if ((code = inDrag) and (whichWindow <> nil)) then
  561.                             begin
  562.                                 tempRect := gScreenBitsBounds;
  563.                                 SetRect(tempRect, tempRect.left + 10, tempRect.top + 25, tempRect.right - 10, tempRect.bottom - 10);
  564.                                 DragWindow(whichWindow, myEvent.where, tempRect);
  565.                             end
  566.                         else if (code = inGrow) then
  567.                             begin
  568.                                 SetPort(whichWindow);
  569.  
  570.                                 myPt := myEvent.where;
  571.                                 GlobalToLocal(myPt);
  572.  
  573.                                 OldRect.left := whichWindow^.portRect.left;
  574.                                 OldRect.right := whichWindow^.portRect.right;
  575.                                 OldRect.top := whichWindow^.portRect.top;
  576.                                 OldRect.bottom := whichWindow^.portRect.bottom;
  577.  
  578.                                 SetRect(tempRect, 15, 15, (gScreenBitsBounds.right - gScreenBitsBounds.left), (gScreenBitsBounds.bottom - gScreenBitsBounds.top) - 20);
  579.                                 mResult := GrowWindow(whichWindow, myEvent.where, tempRect);
  580.                                 SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);
  581.  
  582.                                 SetPort(whichWindow);
  583.  
  584.                                 SetRect(tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15);
  585.                                 EraseRect(tempRect);
  586.                                 InvalRect(tempRect);
  587.                                 SetRect(tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);
  588.                                 EraseRect(tempRect);
  589.                                 InvalRect(tempRect);
  590.                                 DrawGrowIcon(whichWindow);
  591.                             end
  592.                         else if (code = inGoAway) then
  593.                             begin
  594.                                 stillInGoAway := TrackGoAway(whichWindow, myEvent.where);
  595.                                 if (stillInGoAway = TRUE) then
  596.  
  597.                                     case GetWRefCon(whichWindow) of
  598.                                         1: 
  599.                                             Close_P_D_Maze(whichWindow, theInput);
  600.                                     end; {case}
  601.                             end
  602.                         else if (code = inContent) then
  603.                             if whichWindow <> FrontWindow then
  604.                                 SelectWindow(whichWindow)
  605.                             else
  606.                                 begin
  607.                                     SetPort(whichWindow);
  608.                                     case (GetWRefCon(whichWindow)) of
  609.                                         1: 
  610.                                             Do_P_D_Maze(myEvent, theInput);
  611.                                     end;
  612.                                 end
  613.                         else if (code = inSysWindow) then
  614.                             begin
  615.                                 SystemClick(myEvent, whichWindow);
  616.                             end
  617.                         else if ((code = inZoomIn) or (code = inZoomOut)) then
  618.                             if whichWindow <> nil then
  619.                                 begin
  620.                                     SetPort(whichWindow);
  621.  
  622.                                     myPt := myEvent.where;
  623.                                     GlobalToLocal(myPt);
  624.  
  625.                                     if (TrackBox(whichWindow, myPt, code) = TRUE) then
  626.                                         begin
  627.                                             ZoomWindow(whichWindow, code, TRUE);
  628.                                             SetRect(tempRect, 0, 0, 32000, 32000);
  629.                                             EraseRect(tempRect);
  630.                                             InvalRect(tempRect);
  631.                                         end;
  632.                                 end;
  633.  
  634.                     keyDown, autoKey: 
  635.                         begin
  636.                             ch := Char(BAnd(myEvent.message, charCodeMask));
  637.                             mResult := MenuKey(ch);
  638.                             theMenu := HiWord(mResult);
  639.                             theItem := LoWord(mResult);
  640.                             if (theMenu <> 0) then
  641.                                 HandleMenu(doneFlag, theMenu, theItem, theInput);
  642.                         end;
  643.  
  644.                     updateEvt: 
  645.                         begin
  646.                             whichWindow := WindowPtr(myEvent.message);
  647.                             GetPort(SavePort);
  648.                             BeginUpdate(whichWindow);
  649.                             SetPort(whichWindow);
  650.                             case (GetWRefCon(whichWindow)) of
  651.                                 1: 
  652.                                     UpDate_P_D_Maze(whichWindow);
  653.                             end;
  654.                             EndUpdate(whichWindow);
  655.                             SetPort(SavePort);
  656.                         end;
  657.  
  658.                     diskEvt: 
  659.                         if (HiWord(myEvent.message) <> 0) then
  660.                             begin
  661.                                 myEvent.where.h := ((gScreenBitsBounds.right - gScreenBitsBounds.left) div 2) - (304 div 2);
  662.                                 myEvent.where.v := ((gScreenBitsBounds.bottom - gScreenBitsBounds.top) div 3) - (104 div 2);
  663.                                 InitCursor;
  664.                                 theItem := DIBadMount(myEvent.where, myEvent.message);
  665.                             end;
  666.  
  667.                     {app1Evt}
  668.                     12: 
  669.                         if (HiWord(myEvent.message) = 1) and (LoWord(myEvent.message) = 1) then
  670.                             Open_P_D_Maze(theInput)
  671.                         else if (HiWord(myEvent.message) = 2) and (LoWord(myEvent.message) = 1) then
  672.                             Close_P_D_Maze(WindowPtr(-1), theInput);
  673.                     activateEvt: 
  674.                         if (whichWindow <> nil) and (BAnd(myEvent.modifiers, activeFlag) <> 0) then
  675.                             begin
  676.                                 SelectWindow(whichWindow);
  677.                             end;
  678.                 end;
  679.             end;
  680.     until doneFlag;
  681. end.